import os
import glob


'''
检查数据完整性：气动力/姿态角/绳拉力/绳长编码器
'''
def check_e(file_list, model, dataset_prefix):

    file_list_exist = []

    MODEL = model
    DATASET_PREFIX = dataset_prefix

    AERO_DIR = DATASET_PREFIX + MODEL + "/AERO/"
    ANGLE_DIR = DATASET_PREFIX + MODEL + "/ANGLE/"
    TENSION_DIR = DATASET_PREFIX + MODEL + "/TENSION/"
    ENCODER_DIR = DATASET_PREFIX + MODEL + "/ENCODER/"

    for file in file_list:
        flag = 0

        if(model=="F22" or model=="F22_STATIC" or model=="F22_10"):
            # 检查气动力数据
            if os.path.exists(AERO_DIR + file + "_NW.TXT") == False:
                flag = 1
                print(file + "数据缺失：气动力无风")
            if os.path.exists(AERO_DIR + file + "_W.TXT") == False:
                flag = 1
                print(file + "数据缺失：气动力有风")

            # 检查绳拉力数据
            if len(glob.glob(TENSION_DIR + file + "_NW*.txt")) == 0:
                flag = 1
                print(file + "数据缺失：绳拉力无风")
            if len(glob.glob(TENSION_DIR + file + "_W*.txt")) == 0:
                flag = 1
                print(file + "数据缺失：绳拉力有风")

            # 检查绳编码器数据
            if len(glob.glob(ENCODER_DIR + file + "_NW*.txt")) == 0:
                flag = 1
                print(file + "数据缺失：绳编码器无风")
            if len(glob.glob(ENCODER_DIR + file + "_W*.txt")) == 0:
                flag = 1
                print(file + "数据缺失：绳编码器有风")

            # 检查姿态角数据
            if len(glob.glob(ANGLE_DIR + file + "_NW*.csv")) == 0:
                flag = 1
                print(file + "数据缺失：姿态角无风")
            if len(glob.glob(ANGLE_DIR + file + "_W*.csv")) == 0:
                flag = 1
                print(file + "数据缺失：姿态角有风")


            if flag==0:
                file_list_exist.append(file)
            else:
                print("--------")
        else:
            # 检查气动力数据
            if os.path.exists(AERO_DIR + file + "_NW.TXT") == False:
                flag = 1
                print(file + "数据缺失：气动力无风")
            if os.path.exists(AERO_DIR + file + "_W.TXT") == False:
                flag = 1
                print(file + "数据缺失：气动力有风")

            # 检查绳拉力数据
            if len(glob.glob(TENSION_DIR + file + "_NW.txt")) == 0:
                flag = 1
                print(file + "数据缺失：绳拉力无风")
            if len(glob.glob(TENSION_DIR + file + "_W.txt")) == 0:
                flag = 1
                print(file + "数据缺失：绳拉力有风")

            # 检查姿态角数据
            if len(glob.glob(ANGLE_DIR + file + "_NW.csv")) == 0:
                flag = 1
                print(file + "数据缺失：姿态角无风")
            if len(glob.glob(ANGLE_DIR + file + "_W.csv")) == 0:
                flag = 1
                print(file + "数据缺失：姿态角有风")


            if flag==0:
                file_list_exist.append(file)
            else:
                print("--------")

    print('失败数量: ' + str(len(file_list)-len(file_list_exist)))
    print('读取数量: ' + str(len(file_list_exist)))
    # print(str(file_list_exist))

    return file_list_exist